package com.ruangong.GitClient.Test.GitHubAPITest;

import com.ruangong.GitClient.GitHubAPI.GitHubUser;
import com.ruangong.GitClient.GitHubAPI.MoMingUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * 用于测试GitHub API的查询仓库功能。
 * 可以根据Open API的URL获取仓库的基本信息。
 */
public class Test2 {
    public static void main(String[] args)throws Exception{
        GitHubUser gitHubUser =new GitHubUser("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");
        gitHubUser.showInfo();
//        String repoInfo = MoMingUtil.getRepositoryInfo("https://api.github.com/repos/hmkcode/Android");
//        String repoInfo = MoMingUtil.getRepositoryInfo("https://api.github.com/repos/SilverXQI/Silver_Python");
//        String repoInfo = MoMingUtil.getRepositoryInfo("hmkcode", "Android");
//        String repoInfo = MoMingUtil.getRepositoryInfo("SilverXQI", "Silver_Python");
//        GitHubRepository repo = GitHubRepository.fromJson(repoInfo);
//        System.out.println(repo.toString());
        String response = "access_token=ghu_fDe13XcY41desZPQacpeZVFPb7tBkN14rBvb&expires_in=28800&refresh_token=ghr_I8Xz3KgoH8gGUFdqsCQRJ6f3Vf65lbV6fANPg8E9GptiJUZYaS5QhorzKC0Dw6waso8QrJ2sOUNX&refresh_token_expires_in=15897600&scope=&token_type=bearer";
        Map<String, String> params = new HashMap<>();
        String[] pairs = response.split("&");
        for (String pair : pairs) {
            String[] keyValue = pair.split("=");
            if (keyValue.length > 1) {
                params.put(keyValue[0], keyValue[1]);
            } else {
                params.put(keyValue[0], ""); // Assume empty string if no value is present
            }
        }

        String accessToken = params.get("access_token");
        System.out.println("Access token: " + accessToken);
        String refreshToken = params.get("refresh_token");
        System.out.println("Refresh token: " + refreshToken);
        int expiresIn = Integer.parseInt(params.get("expires_in"));
        System.out.println("Expires in: " + expiresIn);
        int refreshTokenExpiresIn = Integer.parseInt(params.get("refresh_token_expires_in"));
        System.out.println("Refresh token expires in: " + refreshTokenExpiresIn);


        MoMingUtil.fetchPrivateRepos(accessToken);
    }

}
